package com.xin.spring.project.xml.service.impl;

import com.xin.spring.project.xml.dao.UserDao;
import com.xin.spring.project.xml.model.User;
import com.xin.spring.project.xml.service.ITestService;

import java.util.Objects;

/**
 * 具体测试服务
 *
 * @author xinyue
 */
public class TestServiceImpl implements ITestService {

    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 新增用户
     *
     * @param user 用户
     * @return 结果
     */
    @Override
    public Integer insertUser(User user) throws Exception {
        User dbUser = userDao.queryUserByName(user.getName());
        if(Objects.isNull(dbUser) || Objects.isNull(dbUser.getId())){
            return userDao.insertUser(user);
        }
        return 0;
    }
}
